inFileName$  = RequestFile("Select first file of animation", "Image Files: png,jpg,bmp")
outFileName$ = RequestFile("Select output file name", "PNG File: png", True)

newSpace  = 1
lastSpace = 0

While newSpace
	
	lastSpace = newSpace
	newSpace  = Instr(inFileName$, " ", lastSpace + 1)
	
Wend

prefix$    = Left$(inFileName$, lastSpace)
extension$ = Right$(inFileName$, 4)

frameList:TList = New TList

sheetWidth  = 0
sheetHeight = 0

frameNum = 1

Graphics 320, 240

Repeat

	frameFileName$ = prefix$ + Replace$(RSet$(String(frameNum), 2), " ", "0") + extension$
	
	frame:TPixmap = LoadPixmapPNG(frameFileName$)
	
	If Not frame Then Exit
	
	sheetWidth = sheetWidth + PixmapWidth(frame)
	If PixmapHeight(frame) > sheetHeight Then sheetHeight = PixmapHeight(frame)
	
	frameList.AddLast(frame)

	frameNum = frameNum + 1
	
Forever

sheetImage = CreatePixmap(sheetWidth, sheetHeight, PF_BGRA8888)

ClearPixels(sheetImage)

x = 0

For frame:TPixmap = EachIn frameList
	
	For py = 0 To PixmapHeight(frame) - 1
	
		For px = 0 To PixmapWidth(frame) - 1
		
			c = ReadPixel(frame, px, py)
			WritePixel(sheetImage, px + x, py, c)
			
		Next
		
	Next
	
	x = x + PixmapWidth(frame)
	
Next

SavePixmapPNG(sheetImage, outFileName$, 9)

End
